package org.agile2soft.nexoma.dao.hibernate;

import java.util.List;

import org.agile2soft.nexoma.dao.ServiceDAO;
import org.agile2soft.nexoma.entity.Service;
import org.agile2soft.nexoma.entity.ServicesGroup;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import br.com.arsmachina.dao.hibernate.GenericDAOImpl;

public class ServiceDAOImpl extends GenericDAOImpl <Service,Integer> implements ServiceDAO {

    public ServiceDAOImpl(SessionFactory sessionFactory) {
        super(sessionFactory);
    }

    @SuppressWarnings("unchecked")
    public List<Service> findByGroup(Integer id) {
        Criteria c = createCriteria();
        c.add(Restrictions.eq("group.id",id));
        c.addOrder(Order.asc("name"));
        return (List<Service>)c.list();
    }

    @SuppressWarnings("unchecked")
    public List<Service> findByGroup(ServicesGroup group) {
        Criteria c = createCriteria();
        c.add(Restrictions.eq("group",group));
        c.addOrder(Order.asc("name"));
        return c.list();
    }

}
